package hu.ozeki.quitar;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class OzSmsUtil {

	private static int transactionID = -1;
	protected static int getNextTransID() {
		transactionID += 2;
		if (transactionID > 32768) transactionID = 1;
			return transactionID;
	}
	
	private static String randomString(int size, boolean lowerCase){
		Random random = new Random();
		StringBuilder builder = new StringBuilder();

		for (int i = 0; i < size; i++){
			char ch = (char)(int)(26.0D * random.nextDouble() + 65.0D);
			builder.append(ch);
		}

		if (lowerCase)
			return builder.toString().toLowerCase();

		return builder.toString();
	}
	
	protected static String makeMessageID(){
		return randomString(8, false);
	}

	protected static Map<String, String> getQueryMap(String query) throws UnsupportedEncodingException{
		String[] params = query.split("&");
		Map map = new HashMap();
		for (String param : params){
			if (param.split("=").length == 2) {
				String name = URLDecoder.decode(param.split("=")[0], "UTF-8");
				String value = URLDecoder.decode(param.split("=")[1], "UTF-8");
				map.put(name, value);
			}
		}

		return map;
	}

	protected static OzSMSMessage smsFromPdu(Map<String, String> map, String fieldprefix){
		OzSMSMessage sms = new OzSMSMessage();
		try {
			sms.messageId = ((String)map.get(fieldprefix + ".messageid"));
			sms.sender = ((String)map.get(fieldprefix + ".originator"));
			sms.receiver = ((String)map.get(fieldprefix + ".recipient"));
			sms.messageData = ((String)map.get(fieldprefix + ".messagedata"));
			sms.messageType = ((String)map.get(fieldprefix + ".messagetype"));
			sms.serviceProvider = ((String)map.get(fieldprefix + ".serviceprovider"));
			sms.errorCode = Integer.parseInt((String)map.get(fieldprefix + ".statuscode"));
			sms.errorMessage = ((String)map.get(fieldprefix + ".statusmessage"));
		}
		catch (Exception localException){
		}
		return sms;
	}
 }

/* Location:           C:\Users\vGarnica\Documents\docOffice2013\java\OzekiSmsClient.jar
 * Qualified Name:     hu.ozeki.OzSmsUtil
 * JD-Core Version:    0.6.2
 */